package com.boomsecret.annotation;

import org.assertj.core.internal.cglib.proxy.Enhancer;
import org.assertj.core.internal.cglib.proxy.MethodInterceptor;
import org.assertj.core.internal.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * Created by wangjinliang on 2018/1/16.
 */
public class AnnotationProxy<T> implements MethodInterceptor {

    private T target;

    public T proxy(T target) {
        this.target = target;
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(target.getClass());
        enhancer.setCallback(this);
        return (T) enhancer.create();
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        Object result = methodProxy.invoke(target, objects);
        UseCaseAnnotationHandler.countMethodInvokeNumber(method);
        return result;
    }
}
